//明天想优化策略
let height = [0,1,0,2,1,0,1,3,2,1,2,1]
var trap = function(height) {
    let max=0;
    let result=0
  for(let i=0;i<height.length;i++){
    max=max>height[i]?max:height[i]
  }  

  
  for(let j=1;j<=max;j++){
    let left=0
    let right=height.length-1
    while(height[left]<j){
        left++
    }
    while(height[right]<j){
        right--
    }
    for(let i=left+1;i<right;i++){
        if(height[i]<j){
            result++
        }
  } 
  }
  return result
};
console.log(trap(height));
